package com.service.lx;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.lx.BILLRECORD_copyDAO;
import com.dao.lx.RepairorderDAO;
import com.entity.BILLRECORD_copy;
import com.entity.Repairorder;
import com.service.ServiceException;


@Service
@Transactional(rollbackFor = Exception.class)
public class BILLRECORD_copyService {
	@Autowired
	private BILLRECORD_copyDAO BILLRECORD_copyDAO;
	@Autowired
	private RepairorderDAO repairorderDAO;
	/**
	 * 添加/修改/逻辑删除
	 * @param notelist
	 * @throws ServiceException
	 */
	public void addAndUpdateBILLRECORD_copy(BILLRECORD_copy BILLRECORD_copy) throws ServiceException{
		try {
			//判断维修工单是否存在
			if(BILLRECORD_copy.getRepairorderId()!=null){
				Repairorder repairorder=repairorderDAO.findOne(BILLRECORD_copy.getRepairorderId());
				if(repairorder!=null){
					BILLRECORD_copy.setRepairorder(repairorder);
				}else{
					BILLRECORD_copy.setRepairorder(null);
				}
			}
			BILLRECORD_copyDAO.save(BILLRECORD_copy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 删除
	 * @param brId
	 * @throws ServiceException
	 */
	public void deleteBILLRECORD_copy(Long brId) throws ServiceException{
		try {
			BILLRECORD_copyDAO.delete(brId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 单条查询
	 * @param notelistId
	 * @return
	 */
	public BILLRECORD_copy findOne(Long brId) {
		return BILLRECORD_copyDAO.findOne(brId);
	}
	
	/**
	 * 根据维修工单id查询
	 * @param notelistId
	 * @return
	 */
	public List<BILLRECORD_copy> findAllByRepairorderId(Long repairorderId) {
		Repairorder repairorder=repairorderDAO.findOne(repairorderId);
		return BILLRECORD_copyDAO.queryByRepairorder(repairorder);
	}

}
